/**
 * Created by zqk on 2018/4/16.
 */
$(document).ready(function () {
    var iProjectId=addressUri.getParam('iProjectId');
    var selectProjectGrade=addressUri.getParam('selectProjectGrade');
    var selectProjectId=addressUri.getParam('selectProjectId');
    var trackList= $('#trackTasksList');
    trackList.datagrid({
        url:moduleUrl+'task/getTrackTaskList',
        queryParams: {
            iProjectId:iProjectId,
            'selectProjectGrade':selectProjectGrade,
            'selectProjectId':selectProjectId,
        },
        method: 'post',
        rownumbers: true,
        pagination: true,
        pageSize: 20,
        pageList: [20,50,100,200],
        idField: 'iTTId',
        singleSelect:false,
        frozenColumns:[[
            {field:'ck',checkbox:true},
            {field:'iTTId',title:'iTTId',hidden:true},
            {field:'sTaskName',title:'任务名称',width:100},
        ]],
        columns:[[
            {field:'sTaskContent',title:'任务内容',width:2000},
        ]],

    });

    $('#bt_list_search').click(function(){
        var iTaskType = $('#iTaskType').val();
        var sTaskName = $('#sTaskName').val();//获取input值
        trackList.datagrid('load',{iTaskType:iTaskType,sTaskName:sTaskName,iProjectId:iProjectId,});
    });

    $('#bt_modal_confirm').click(function () {
        xhExtra.setBtnLoading($('#bt_modal_confirm',parent.document));
        $('#bt_modal_confirm',parent.document).addClass('disabled');
        myWindow.initPopUp({title: '批量导入任务', text: '确认批量导入任务吗?'},function () {
            var selections = trackList.datagrid('getSelections');
            var iTTIds = [];
            for(k in selections ){
                iTTIds.push(selections[k].iTTId)
            }
            var data = {
                'iProjectId':iProjectId ,
                'selectProjectGrade':selectProjectGrade,
                'selectProjectId':selectProjectId,
                'iTTIds':iTTIds
            }
            $.ajax({
                url:moduleUrl+'task/addMultiTask',
                dataType: "JSON",
                data:data,
                type:'POST',
                success:function (data) {
                    window.top.xhTop.showSuccess(
                        data.msg
                    );
                    window.top.xhTop.closeModal();
                    window.top.xhTop.getActiveFrame().taskList.treegrid('reload');
                },
                error:function (data) {
                    window.top.xhTop.showError(
                        data.responseJSON.error,
                        data.responseJSON.msg
                    );
                }
            });
        })

    });

    $('#bt_modal_close').click(function () {
        window.top.xhTop.closeModal();
    })

});